<?php

/**
 *  autoloader
 *
 *  Replacement for __autoload
 *
 *  @param      string      class   name of the class we want to load
 *  @return     bool                True/False
 */
function autoloader($class) {
    if (file_exists(FACADE_PATH .$class .".class.php")) {
        if (include_once(FACADE_PATH .$class .".class.php")) {
            return true;
        } else {
            // debug: could not include the requested class file
            return false;
        }
    }
    elseif (file_exists(APP_CONTROL_PATH .$class .".class.php")) {
        if (include_once(APP_CONTROL_PATH .$class .".class.php")) {
            return true;
        } else {
            // debug: could not include the requested class file
            return false;
        }
    }
    elseif (file_exists(APP_FACADE_PATH .$class .".class.php")) {
        if (include_once(APP_FACADE_PATH .$class .".class.php")) {
            return true;
        } else {
            // debug: could not include the requested class file
            return false;
        }
    }
    elseif (file_exists(SERVICE_PATH .$class .".class.php")) {
        if (include_once(SERVICE_PATH .$class .".class.php")) {
            return true;
        } else {
            // debug: could not include the requested class file
            return false;
        }
    }
    elseif (file_exists(UTILS_PATH .$class .".class.php")) {
        if (include_once(UTILS_PATH .$class .".class.php")) {
            return true;
        } else {
            // debug: could not include the requested class file
            return false;
        }
    }
    elseif (file_exists(THIRD_PARTY_LIB .$class .".class.php")) {
        if (include_once(THIRD_PARTY_LIB .$class .".class.php")) {
            return true;
        } else {
            // debug: could not include the requested class file
            return false;
        }
    }
    elseif (file_exists(CONTROL_PATH .$class .".class.php")) {
        if (include_once(CONTROL_PATH .$class .".class.php")) {
            return true;
        } else {
            // debug: could not include the requested class file
            return false;
        }
    }
    elseif (file_exists(VALIDATION_PATH .$class .".class.php")) {
        if (include_once(VALIDATION_PATH .$class .".class.php")) {
            return true;
        } else {
            // debug: could not include the requested class file
            return false;
        }
    } else {
        // debug: class file does not exist
        global $request;
        $indexControl = new IndexControl($request);
        $indexControl->PageNotFound();
        exit();
    }
}
// Register the autoloader function as a replacement for __autoload
spl_autoload_register("autoloader");
?>